home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / DTMLMETHOD.PY < prev    next >
Encoding:
Text File  |  2000-10-31  |  8.1 KB  |  203 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64.  
  65. def manage_addDTMLMethod(id, title):
  66.     """
  67.     Add a DTML Method to the current ObjectManager
  68.     """
  69.  
  70. class DTMLMethod:
  71.     """
  72.     A DTML Method is a Zope object that contains and executes DTML
  73.     code. It can act as a template to display other objects. It can
  74.     also hold small pieces of content which are inserted into other
  75.     DTML Documents or DTML Methods.
  76.  
  77.     The DTML Method's id is available via the 'document_id'
  78.     variable and the title is available via the 'document_title'
  79.     variable.
  80.     
  81.     """
  82.  
  83.     __extends__=('OFSP.ObjectManagerItem.ObjectManagerItem',)
  84.     
  85.     def __call__(client=None, REQUEST={}, **kw):
  86.         """
  87.  
  88.         Calling a DTMLMethod causes the Method to interpret the DTML
  89.         code that it contains.  The method returns the result of the
  90.         interpretation, which can be any kind of object.
  91.  
  92.         To accomplish its task, DTML Method often needs to resolve various
  93.         names into objects.  For example, when the code '<dtml-var
  94.         spam>' is executed, the DTML engine tries to resolve the name
  95.         'spam'.
  96.  
  97.         In order to resolve names, the Method must be passed a
  98.         namespace to look them up in.  This can be done several ways:
  99.  
  100.           * By passing a 'client' object -- If the argument 'client' is
  101.             passed, then names are looked up as attributes on the
  102.             argument.
  103.  
  104.           * By passing a 'REQUEST' mapping -- If the argument 'REQUEST'
  105.             is passed, then names are looked up as items on the
  106.             argument.  If the object is not a mapping, an TypeError
  107.             will be raised when a name lookup is attempted.
  108.  
  109.           * By passing keyword arguments -- names and their values can
  110.             be passed as keyword arguments to the Method.
  111.  
  112.         The namespace given to a DTML Method is the composite of
  113.         these three methods.  You can pass any number of them or none
  114.         at all. Names will be looked up first in the keyword argument,
  115.         next in the client and finally in the mapping.
  116.  
  117.         Unlike DTMLDocuments, DTMLMethods do not look up names in
  118.         their own instance dictionary.
  119.  
  120.         Passing in a namespace to a DTML Method is often referred to
  121.         as providing the Method with a *context*.
  122.  
  123.         DTML Methods are called three ways:
  124.  
  125.           From DTML -- A DTML Method can be called from another DTML
  126.             Method or Document::
  127.  
  128.               <dtml-var standard_html_header>
  129.                 <dtml-var aDTMLMethod>
  130.               <dtml-var standard_html_footer>
  131.  
  132.             In this example, the Method 'aDTMLMethod' is being called
  133.             from another DTML object by name.  The calling method
  134.             passes the value 'this' as the client argument and the
  135.             current DTML names pace as the REQUEST argument.  The above
  136.             is identical to this following usage in a DTML Python
  137.             expression::
  138.  
  139.               <dtml-var standard_html_header>
  140.                 <dtml-var "aDTMLMethod(_.None, _)">
  141.               <dtml-var standard_html_footer>
  142.  
  143.           From Python -- Products, External Methods, and PythonMethods 
  144.             can call a DTML Method in the same way as calling a DTML
  145.             Method from a Python expression in DTML; as shown in the
  146.             previous example.
  147.  
  148.           By the Publisher -- When the URL of a DTML Method is fetched 
  149.             from Zope, the DTML Method is called by the publisher.
  150.             The REQUEST object is passes as the second argument to the 
  151.             Method.
  152.           
  153.         Permission -- 'View'
  154.         """
  155.  
  156.     def manage_edit(data, title):
  157.         """
  158.         Change the DTML Method, replacing its contents with 'data' and
  159.         changing its title.
  160.         
  161.         The data argument may be a file object or a string.
  162.         
  163.         Permission -- 'Change DTML Methods'
  164.         """
  165.         
  166.     def document_src():
  167.         """
  168.         Returns the unrendered source text of the DTML Method.
  169.         
  170.         Permission -- 'View management screens'
  171.         """
  172.         
  173.     def get_size():
  174.         """
  175.         Returns the size of the unrendered source text of the DTML
  176.         Method in bytes.
  177.  
  178.         Permission -- 'View'
  179.         """
  180.         
  181.     __constructor__ = manage_addDTMLMethod
  182.